package com.zhongkai.controller;

import com.zhongkai.app.service.AnomalyService;
import com.zhongkai.model.utils.ZhongkaiResult;
import com.zhongkai.model3.Chinaset;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * 异常设备列表
 * */
@Controller
public class AnomalyController {


    @Autowired
    private AnomalyService anomalyService;


    /**
     * 报警设备列表
     *
     * @param status 状态
     * @param page   当前页数
     * @param rows   每页数据条数
     */
    @RequestMapping(value = "/anomaly/unit/list", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult unit_anomaly_list(
            String status, @RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "0") Integer rows

    ) {



        ZhongkaiResult zhongkaiResult = anomalyService.unit_anomaly_list(
                status
                , page
                , rows


        );

        return zhongkaiResult;
    }


    /**
     * 异常设备派单
     *
     * @param unit_uuid 设备uuid
     * @param get_name  接单人员姓名
     * @param get_uuid  接单人员UUId
     */
    @RequestMapping(value = "/anomaly/assign", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult assign_anomaly(
            String unit_uuid, String get_name, String get_uuid
            , HttpServletRequest httpServletRequest

    ) {


        Chinaset chinaset = (Chinaset) httpServletRequest.getAttribute("user");
        ZhongkaiResult zhongkaiResult = anomalyService.assign_anomaly(
                unit_uuid,
                chinaset.getSetName()
                ,chinaset.getUuid()
                , get_name
                , get_uuid


        );

        return zhongkaiResult;
    }


    /**
     * 维修用户列表
     * @param page      当前页数
     * @param rows      每页数据条数
     */
    @RequestMapping(value = "/anomaly/as/list", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult as_repair_list(
            @RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "0") Integer rows

    ) {


        ZhongkaiResult zhongkaiResult = null;
        try {
            zhongkaiResult = anomalyService.as_repair_list(
                    page
                    , rows
            );
        } catch (Exception e) {
            e.printStackTrace();
            return ZhongkaiResult.build(405, "查询失败");

        }

        return zhongkaiResult;
    }




    /**
     * 撤销维修
     *
     * @param unit_uuid 设备uuid
     */
    @RequestMapping(value = "/anomaly/as/repeal", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult annul_anomaly(
            String unit_uuid

    ) {


        ZhongkaiResult zhongkaiResult = null;
        try {
            zhongkaiResult = anomalyService.annul_anomaly(
                    unit_uuid
            );
        } catch (Exception e) {
            e.printStackTrace();
            return ZhongkaiResult.build(400, "撤销失败,请联系管理员");
        }

        return zhongkaiResult;
    }

}
